package com.renke.enml;

import java.math.BigDecimal;
import java.math.MathContext;

/**
 * @author robson.enke
 */
public class NumberLiteral extends Expression {

	private final int signal;
	private BigDecimal number;

	NumberLiteral(String value) {
		super(value);
		signal = 1;
	}

	public boolean isDecimal() {
		return getValue().contains(".");
	}

	public long longValue() {
		return bigDecimalValue().longValue();
	}

	public double doubleValue() {
		return bigDecimalValue().doubleValue();
	}

	public BigDecimal bigDecimalValue() {
		if (number == null) {
			number = new BigDecimal(getValue(), MathContext.DECIMAL128).multiply(new BigDecimal(signal));
		}
		return number;
	}

	@Override
	public String toString() {
		return (signal == -1 ? "-" : "") + getValue();
	}
}
